<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ page session="true" %>
<%@ page import="javax.portlet.*"%>
<%@ page import="pits.dto.EditTakenProjectInfoDTO" %>
<%@ page import="pits.dao.EditTakenProjectInfoDAO" %>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<portlet:defineObjects />

<html>

<script>
	var existedRoleList = "";

	function isIn(container, str, splitter) {
		var arr = container.split(splitter);
		for (i = 0; i < arr.length; i++) {
			if (arr[i] == str) return true;
		}
		return false; 
	}
	
	function getForm(namespace, name) {
		return document.forms[namespace + name];
	}

	function submitForm(namespace, name, action) {
		var frm = getForm(namespace, name);
		frm.txtAction.value = action;
		frm.submitLink.value = "EditTakenProjectInfo.jsp";
		//document.write(existedRoleList);
		//new
		if (name != "myForm") {
			if (frm.selectRole.value == "Other") {
				frm.role.value = frm.otherRole.value;
			}
			else {
				frm.role.value = frm.selectRole.value;
			}
		}
		frm.submit();
	}
</script>

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Personal Information Tracking System</title>
<meta name="keywords" content="" />
<meta name="description" content="" />

<script type="text/javascript" src='<%=renderRequest.getContextPath() + "/js/simpletreemenu.js" %>'>
</script>
<link rel="stylesheet" type="text/css" href='<%=renderRequest.getContextPath() + "/style/simpletree.css" %>' />

<script type="text/javascript" src='<%=renderRequest.getContextPath() + "/js/calendarDateInput.js" %>'></script>

<link href='<%=renderRequest.getContextPath() + "/style/style.css" %>' rel="stylesheet" type="text/css" media="screen" /></head>

<body>
<form name="<portlet:namespace/>myForm" action="<portlet:actionURL/>" method="POST">
<input type="hidden" name="txtAction"/>
<input type="hidden" name="submitLink"/>
<p align="right">
	You are logging in as 
	<a href="#" onclick="submitForm('<portlet:namespace/>', 'myForm', 'getEmployeeInfo')"><b>${sessionScope.userName}</b></a>
	! &nbsp;
	<a href="#" onclick="submitForm('<portlet:namespace/>', 'myForm', 'home')">Home</a>
	| &nbsp;
	<a href="#" onclick="submitForm('<portlet:namespace/>', 'myForm', 'logout')">Logout</a>
</p>
</form>

<form name="<portlet:namespace/>editTakenProjectInfoForm" action="<portlet:actionURL/>" method="POST">
<input type="hidden" name="txtAction"/>
<input type="hidden" name="submitLink"/>
<table align="center">
	<tr class="title">
		<td colspan="2">
			<img src='<%=renderRequest.getContextPath() + "/img/HCMUTLogo.jpg" %>' />
			<h1><a href="#">Personal information tracking system </a></h1>
			<p>exploit the value of data</p>
			<hr />
		</td>
	</tr>
	
	<tr>	
		<td>
			<table border="1">
				<tr>
					<td><h2 class="title">Project Experience	Information</h2></td>
				</tr>
				<tr>
					<td>
					<%
					EditTakenProjectInfoDTO takenProject = new EditTakenProjectInfoDAO().getData("" + session.getAttribute("projectID"), "" + session.getAttribute("empID"));
					%>
						<table border="1" width="100%">							
							<tr>
								<td align="left" valign="bottom">&nbsp;Project Name </td>
								<td align="left" valign="middle" colspan="2"><%=takenProject.getName() %></td>
							</tr><tr>
								<td align="left" valign="bottom">&nbsp;Department&nbsp;</td>
								<td align="left" valign="middle" colspan="2"><%=takenProject.getDepartment() %></td>
							</tr>
							
							<tr>
								<td align="left" valign="middle" rowspan="2">&nbsp;Working Period&nbsp;</td>
								<td align="left" valign="bottom">From</td>
								<td align="left" valign="middle">&nbsp;
								<script>DateInput('periodFrom', true, 'DD/MM/YYYY', '<%= request.getContextPath() %>', '<%=takenProject.getPeriodFrom() %>');</script>
							</td>								 
							</tr>
							
							<tr>
								<td align="left" valign="bottom">&nbsp;To&nbsp;</td>
								<td align="left" valign="bottom">&nbsp;
									<script>DateInput('periodTo', true, 'DD/MM/YYYY', '<%= request.getContextPath() %>', '<%=takenProject.getPeriodTo() %>');</script>
								</td>
							</tr>
							
							<tr>
								<td align="left" valign="bottom">&nbsp;Role&nbsp;</td>
<!--								<td>-->
<!--									<textarea name="txtRole" rows="1"><%=takenProject.getCurrentRoleName() %></textarea>-->
<!--								</td>-->
								<td align="left" valign="middle" colspan="2">
									<input type="hidden" name="role" value='<%=takenProject.getCurrentRoleID() %>'/>
									<select name="selectRole" onchange="
										if(this.value=='Other'){
											this.form.otherRole.style.visibility='visible';
											this.form.otherRole.focus();
										}
										else{
											this.form.otherRole.style.visibility='hidden';
										}
									">
									<%
									for (int i = 0; i < takenProject.getRoleNames().size(); i++) {
									%>
										<option value=<%=takenProject.getRoleIDs().get(i).intValue() %> ><%=takenProject.getRoleNames().get(i) %></option>
									<%
									}
									%>
										<option value="Other">Other</option>
									</select>
									
<!--									<%for (int i = 0; i < takenProject.getRoleNames().size(); i++) {%>-->
<!--									<script type="text/javascript">-->
<!--										existedRoleList += ", " + "<%=takenProject.getRoleNames().get(i) %>";-->
<!--									</script>-->
<!--									<%}%>-->
<!--									<script type="text/javascript">-->
<!--										existedRoleList = existedRoleList.substr(2);-->
<!--									</script>-->
										
									<input name="otherRole" type="text" style="visibility:hidden" />
<!--									<input name="addRole" type="button" value="Add" onclick="-->
<!--										if(this.form.selectRole.value!='Other'){-->
<!--											if(this.form.role.value==''){-->
<!--												this.form.role.value = this.form.selectRole.value;-->
<!--												this.form.txtRole.value = this.form.selectRole.options[this.form.selectRole.selectedIndex].text;-->
<!--											}-->
<!--											else if (!isIn(this.form.role.value, this.form.selectRole.value, ':')) {-->
<!--												this.form.role.value += ':' + this.form.selectRole.value;-->
<!--												this.form.txtRole.value += ', ' + this.form.selectRole.options[this.form.selectRole.selectedIndex].text;-->
<!--											}-->
<!--										}-->
<!--										else if (!isIn(existedRoleList, this.form.otherRole.value, ', ')) {-->
<!--											if(this.form.role.value==''){-->
<!--												this.form.role.value = this.form.otherRole.value;-->
<!--												this.form.txtRole.value = this.form.otherRole.value;-->
<!--											}-->
<!--											else if (!isIn(this.form.txtRole.value, this.form.otherRole.value, ', ')) {-->
<!--												this.form.role.value += ':' + this.form.otherRole.value;-->
<!--												this.form.txtRole.value += ', ' + this.form.otherRole.value;-->
<!--											}-->
<!--										}-->
<!--									"/>-->
								</td>
							</tr>
							
							<tr>
								<td>&nbsp;More Description&nbsp;</td>
							<td colspan="2"><textarea name="description" cols="" rows="2"><%=takenProject.getDescription() %></textarea></td>
							</tr>

							<tr align="left" valign="bottom">
								<td colspan="3">
									<input type="button" value="Update" onclick="
										submitForm('<portlet:namespace/>','editTakenProjectInfoForm','updateTakenProject')
									"/>
							  		<input type="button" value="Cancel" onclick="
							  			submitForm('<portlet:namespace/>','editTakenProjectInfoForm','home')
							  		"/>
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>			
		</td>
	</tr>
	<tr>
		<td colspan="2">
			<div style="clear: both;">&nbsp;</div>
			<div id="footer"><p>Development by HCMUT Project 1 Spring 2010 Group 4</p></div>
		</td>
	</tr>
</table>
</form>
</body>

</html>